#include "crc.h"

uint8_t Crc_CalCrc(uint8_t *p, uint16_t length)
{
    uint8_t i, crc = 0;

    while (length-- != 0)
    {
        for (i=0x80; i!= 0; i/=2)
        {
            if ((crc&0x80) != 0)
            {

                crc *= 2;
                crc ^= CRC_8X;
            }
            else
            {
                crc*= 2;
            }

            if ((*p&i) != 0)
            {

                crc ^= CRC_8X;
            }
        }
        p++;
    }

    return(crc);
}
/*****************************************************************************/
